/*
 * CS_REQ_INVEN_REORDER.cpp
 *
 *  Created on: 2013. 10. 21.
 *      Author: jjaehuny
 */

#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/Space.h"
#include "../../NUtil/SafeArray.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_REQ_INVEN_REORDER(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 * CS_REQ_INVEN_REORDER	0x1600		/// 인벤 재정렬
	{
		u8 u8bag_type;					// 가방타입
		u8 u8bag_sort_type;				/// 0: 레벨별 정렬, 1: 등급별 정렬
	}

	SC_REQ_INVEN_REORDER	0x1601		/// 인벤 재정렬
	{
		s16	ack;	// 1: 성공
	}
	 */

	PREPARE_PACKET;

	if (NULL == pUser->GetSpace() || pUser->GetSpace()->GetData()._spaceType != NLogic::Space::SpaceType::WORLD)
	{
		DEBUGLOG("CS_REQ_INVEN_REORDER NULL == pUser->GetSpace() || pUser->GetSpace()->GetData()._spaceType != NLogic::Space::SpaceType::WORLD");

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(-1);
		pAck->MakePacket(CMD_SC_REQ_INVEN_REORDER);
		pUser->Send(pAck);

		return;
	}

	uint8_t u8bag_type;
	uint8_t u8bag_sort_type;

	* pPacket >> u8bag_type >> u8bag_sort_type;

	NLogic::Bag * pBag = pUser->GetBag(static_cast<INVEN_BAG_TYPE>(u8bag_type));
	if (NULL == pBag)
	{
		DEBUGLOG("CS_REQ_INVEN_REORDER BAG IS NULL bag_type : %d", u8bag_type);

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		* pAck << static_cast<int16_t>(-1);
		pAck->MakePacket(CMD_SC_REQ_INVEN_REORDER);
		pUser->Send(pAck);

		return;
	}

	User::BAG_ORDER & array = pUser->GetBagOrder();
	if (false == array.SetValue(u8bag_type, u8bag_sort_type))
	{
		DEBUGLOG("ERROR CS_REQ_INVEN_REORDER INVALID bag_type : %d", u8bag_type);
	}

	//pUser->Get_array_bag_order_info()[u8bag_type] = u8bag_sort_type;

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << static_cast<int16_t>(1);
	pAck->MakePacket(CMD_SC_REQ_INVEN_REORDER);
	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/







